import add_zero from "./addZero";
//返回固定格式日期
const formatTime = (value, type) => {
  if (value === "") {
    return "";
  }
  let time = "";
  switch (type) {
    case "type_s":
      //时间戳 s
      time = new Date(value * 1000);
      break;
    case "time_date":
    case "time":
      time = new Date(value);
      break;
    case "obj":
    case "obj_date":
      //时间戳 s
      time = value;
      break;
    default:
      break;
  }
  let year = time.getFullYear();
  let month = time.getMonth() + 1;
  let day = time.getDate();
  let hour = time.toTimeString().substring(0, 8);
  if (type.indexOf("date") > -1) {
    return `${year}-${add_zero(month)}-${add_zero(day)}`;
  } else {
    return `${year}-${add_zero(month)}-${add_zero(day)} ${hour}`;
  }
};
export default formatTime;
